import numpy as np
import pytest
from sklearn import config_context

from skfolio.moments import (
    OAS,
    DenoiseCovariance,
    DetoneCovariance,
    EWCovariance,
    EmpiricalCovariance,
    GerberCovariance,
    GraphicalLassoCV,
    ImpliedCovariance,
    LedoitWolf,
    ShrunkCovariance,
)


class TestEmpiricalCovariance:
    def test_empirical_covariance(self, X):
        model = EmpiricalCovariance()
        model.fit(X)
        assert model.covariance_.shape == (20, 20)
        np.testing.assert_almost_equal(model.covariance_, np.cov(X.T))

    def test_empirical_covariance_single(self, X):
        model = EmpiricalCovariance()

        X_truncated = X.iloc[:, :1]
        model.fit(X_truncated)

        assert model.covariance_.shape == (1, 1)
        np.testing.assert_almost_equal(
            model.covariance_, np.cov(X_truncated, rowvar=False)
        )


class TestEWCovariance:
    def test_ew_covariance(self, X):
        model = EWCovariance()
        model.fit(X)
        assert model.covariance_.shape == (20, 20)
        np.testing.assert_almost_equal(
            model.covariance_,
            np.array(
                [
                    [
                        3.34656024e-04,
                        3.73870143e-04,
                        6.88515112e-05,
                        1.93756202e-04,
                        2.03071688e-04,
                        2.42924966e-04,
                        1.73945126e-04,
                        9.63359337e-05,
                        8.46415670e-05,
                        1.44135521e-04,
                        1.11333928e-04,
                        1.21724780e-04,
                        2.12083536e-04,
                        1.00698743e-04,
                        1.07447280e-04,
                        1.10580640e-04,
                        5.52877321e-04,
                        1.14835040e-04,
                        1.45354813e-04,
                        2.20425197e-04,
                    ],
                    [
                        3.73870143e-04,
                        7.22595922e-04,
                        1.79819055e-04,
                        2.04448144e-04,
                        2.89812794e-04,
                        3.16937720e-04,
                        2.04345811e-04,
                        1.19387475e-04,
                        1.75667996e-04,
                        1.62044625e-04,
                        1.98690775e-04,
                        1.00841314e-04,
                        3.17679345e-04,
                        1.17079436e-04,
                        1.09398338e-04,
                        5.16778091e-05,
                        6.27598711e-04,
                        1.19305121e-04,
                        1.64705834e-04,
                        3.04081418e-04,
                    ],
                    [
                        6.88515112e-05,
                        1.79819055e-04,
                        1.04437992e-04,
                        3.74038615e-05,
                        5.77923383e-05,
                        1.00764871e-04,
                        3.16274237e-05,
                        2.89793587e-05,
                        7.37458231e-05,
                        3.54332126e-05,
                        4.71163303e-05,
                        1.40322804e-05,
                        6.85841976e-05,
                        3.20774587e-05,
                        7.48794028e-06,
                        3.33574389e-06,
                        3.81469723e-05,
                        2.89111474e-05,
                        2.63376146e-05,
                        6.44448865e-05,
                    ],
                    [
                        1.93756202e-04,
                        2.04448144e-04,
                        3.74038615e-05,
                        2.75810120e-04,
                        2.08750609e-04,
                        1.55711059e-04,
                        1.29849560e-04,
                        5.73571445e-05,
                        3.85816948e-05,
                        1.12432707e-04,
                        2.31200554e-05,
                        8.17084864e-05,
                        9.51438033e-05,
                        7.44130619e-05,
                        5.12825197e-05,
                        9.58689728e-05,
                        4.98394665e-04,
                        8.13797431e-05,
                        1.24782524e-04,
                        2.02762146e-04,
                    ],
                    [
                        2.03071688e-04,
                        2.89812794e-04,
                        5.77923383e-05,
                        2.08750609e-04,
                        3.23901217e-04,
                        2.00968617e-04,
                        1.47605799e-04,
                        6.97537467e-05,
                        7.15013054e-05,
                        1.28750270e-04,
                        5.82605557e-05,
                        1.01258753e-04,
                        1.54126027e-04,
                        9.87985908e-05,
                        6.88914793e-05,
                        9.16909392e-05,
                        6.05145518e-04,
                        8.58199990e-05,
                        1.53963963e-04,
                        3.04421143e-04,
                    ],
                    [
                        2.42924966e-04,
                        3.16937720e-04,
                        1.00764871e-04,
                        1.55711059e-04,
                        2.00968617e-04,
                        3.33730545e-04,
                        1.21377633e-04,
                        8.10563046e-05,
                        1.09626758e-04,
                        1.31120688e-04,
                        1.01084164e-04,
                        9.20583303e-05,
                        1.63407982e-04,
                        8.80234257e-05,
                        3.63250357e-05,
                        9.77919608e-05,
                        4.07121510e-04,
                        9.29502748e-05,
                        1.53897675e-04,
                        2.11771307e-04,
                    ],
                    [
                        1.73945126e-04,
                        2.04345811e-04,
                        3.16274237e-05,
                        1.29849560e-04,
                        1.47605799e-04,
                        1.21377633e-04,
                        1.43662154e-04,
                        6.07074414e-05,
                        5.13297256e-05,
                        9.46997323e-05,
                        6.32440519e-05,
                        7.46567519e-05,
                        1.36208386e-04,
                        6.06405505e-05,
                        7.37167249e-05,
                        7.38439913e-05,
                        3.74045083e-04,
                        7.71563964e-05,
                        8.57343984e-05,
                        1.51389535e-04,
                    ],
                    [
                        9.63359337e-05,
                        1.19387475e-04,
                        2.89793587e-05,
                        5.73571445e-05,
                        6.97537467e-05,
                        8.10563046e-05,
                        6.07074414e-05,
                        3.83720828e-05,
                        3.21409449e-05,
                        4.72667935e-05,
                        4.23851686e-05,
                        4.46117679e-05,
                        7.07172677e-05,
                        3.06330336e-05,
                        5.31571252e-05,
                        3.39861746e-05,
                        1.44952769e-04,
                        4.02810493e-05,
                        4.94081322e-05,
                        6.83112944e-05,
                    ],
                    [
                        8.46415670e-05,
                        1.75667996e-04,
                        7.37458231e-05,
                        3.85816948e-05,
                        7.15013054e-05,
                        1.09626758e-04,
                        5.13297256e-05,
                        3.21409449e-05,
                        8.10510178e-05,
                        4.60764910e-05,
                        5.14580905e-05,
                        2.45133045e-05,
                        8.82017355e-05,
                        3.96061879e-05,
                        2.76279196e-05,
                        1.62117360e-05,
                        7.73710151e-05,
                        4.34654821e-05,
                        3.83000607e-05,
                        7.81695433e-05,
                    ],
                    [
                        1.44135521e-04,
                        1.62044625e-04,
                        3.54332126e-05,
                        1.12432707e-04,
                        1.28750270e-04,
                        1.31120688e-04,
                        9.46997323e-05,
                        4.72667935e-05,
                        4.60764910e-05,
                        8.57293492e-05,
                        5.40348371e-05,
                        6.29006099e-05,
                        9.16970950e-05,
                        5.95581523e-05,
                        3.93072184e-05,
                        6.78951245e-05,
                        3.11536736e-04,
                        6.88197436e-05,
                        8.21727875e-05,
                        1.33880116e-04,
                    ],
                    [
                        1.11333928e-04,
                        1.98690775e-04,
                        4.71163303e-05,
                        2.31200554e-05,
                        5.82605557e-05,
                        1.01084164e-04,
                        6.32440519e-05,
                        4.23851686e-05,
                        5.14580905e-05,
                        5.40348371e-05,
                        1.26015530e-04,
                        3.98218568e-05,
                        8.90467958e-05,
                        2.96334353e-05,
                        5.18098245e-05,
                        2.03749974e-05,
                        1.44909502e-04,
                        6.47509817e-05,
                        5.05540861e-05,
                        5.92554894e-05,
                    ],
                    [
                        1.21724780e-04,
                        1.00841314e-04,
                        1.40322804e-05,
                        8.17084864e-05,
                        1.01258753e-04,
                        9.20583303e-05,
                        7.46567519e-05,
                        4.46117679e-05,
                        2.45133045e-05,
                        6.29006099e-05,
                        3.98218568e-05,
                        7.46532425e-05,
                        7.20536245e-05,
                        4.37662999e-05,
                        6.29158817e-05,
                        5.67412273e-05,
                        2.08476241e-04,
                        5.29930762e-05,
                        6.39639640e-05,
                        9.05608559e-05,
                    ],
                    [
                        2.12083536e-04,
                        3.17679345e-04,
                        6.85841976e-05,
                        9.51438033e-05,
                        1.54126027e-04,
                        1.63407982e-04,
                        1.36208386e-04,
                        7.07172677e-05,
                        8.82017355e-05,
                        9.16970950e-05,
                        8.90467958e-05,
                        7.20536245e-05,
                        1.97508299e-04,
                        6.44793575e-05,
                        9.65201528e-05,
                        5.31366916e-05,
                        3.33347116e-04,
                        6.87327055e-05,
                        9.48901157e-05,
                        1.63523240e-04,
                    ],
                    [
                        1.00698743e-04,
                        1.17079436e-04,
                        3.20774587e-05,
                        7.44130619e-05,
                        9.87985908e-05,
                        8.80234257e-05,
                        6.06405505e-05,
                        3.06330336e-05,
                        3.96061879e-05,
                        5.95581523e-05,
                        2.96334353e-05,
                        4.37662999e-05,
                        6.44793575e-05,
                        5.07848688e-05,
                        2.01231655e-05,
                        4.58949773e-05,
                        2.06996008e-04,
                        4.61551525e-05,
                        5.45900083e-05,
                        1.04441616e-04,
                    ],
                    [
                        1.07447280e-04,
                        1.09398338e-04,
                        7.48794028e-06,
                        5.12825197e-05,
                        6.88914793e-05,
                        3.63250357e-05,
                        7.37167249e-05,
                        5.31571252e-05,
                        2.76279196e-05,
                        3.93072184e-05,
                        5.18098245e-05,
                        6.29158817e-05,
                        9.65201528e-05,
                        2.01231655e-05,
                        1.75956840e-04,
                        2.90906745e-05,
                        9.85274744e-05,
                        4.43744542e-05,
                        5.40049836e-05,
                        4.88956089e-05,
                    ],
                    [
                        1.10580640e-04,
                        5.16778091e-05,
                        3.33574389e-06,
                        9.58689728e-05,
                        9.16909392e-05,
                        9.77919608e-05,
                        7.38439913e-05,
                        3.39861746e-05,
                        1.62117360e-05,
                        6.78951245e-05,
                        2.03749974e-05,
                        5.67412273e-05,
                        5.31366916e-05,
                        4.58949773e-05,
                        2.90906745e-05,
                        7.42955884e-05,
                        2.54291680e-04,
                        5.49395650e-05,
                        6.84021910e-05,
                        9.78497227e-05,
                    ],
                    [
                        5.52877321e-04,
                        6.27598711e-04,
                        3.81469723e-05,
                        4.98394665e-04,
                        6.05145518e-04,
                        4.07121510e-04,
                        3.74045083e-04,
                        1.44952769e-04,
                        7.73710151e-05,
                        3.11536736e-04,
                        1.44909502e-04,
                        2.08476241e-04,
                        3.33347116e-04,
                        2.06996008e-04,
                        9.85274744e-05,
                        2.54291680e-04,
                        1.81802877e-03,
                        1.96369122e-04,
                        3.46132666e-04,
                        6.47187268e-04,
                    ],
                    [
                        1.14835040e-04,
                        1.19305121e-04,
                        2.89111474e-05,
                        8.13797431e-05,
                        8.58199990e-05,
                        9.29502748e-05,
                        7.71563964e-05,
                        4.02810493e-05,
                        4.34654821e-05,
                        6.88197436e-05,
                        6.47509817e-05,
                        5.29930762e-05,
                        6.87327055e-05,
                        4.61551525e-05,
                        4.43744542e-05,
                        5.49395650e-05,
                        1.96369122e-04,
                        8.10337535e-05,
                        5.61614465e-05,
                        8.58846892e-05,
                    ],
                    [
                        1.45354813e-04,
                        1.64705834e-04,
                        2.63376146e-05,
                        1.24782524e-04,
                        1.53963963e-04,
                        1.53897675e-04,
                        8.57343984e-05,
                        4.94081322e-05,
                        3.83000607e-05,
                        8.21727875e-05,
                        5.05540861e-05,
                        6.39639640e-05,
                        9.48901157e-05,
                        5.45900083e-05,
                        5.40049836e-05,
                        6.84021910e-05,
                        3.46132666e-04,
                        5.61614465e-05,
                        1.12460591e-04,
                        1.54437816e-04,
                    ],
                    [
                        2.20425197e-04,
                        3.04081418e-04,
                        6.44448865e-05,
                        2.02762146e-04,
                        3.04421143e-04,
                        2.11771307e-04,
                        1.51389535e-04,
                        6.83112944e-05,
                        7.81695433e-05,
                        1.33880116e-04,
                        5.92554894e-05,
                        9.05608559e-05,
                        1.63523240e-04,
                        1.04441616e-04,
                        4.88956089e-05,
                        9.78497227e-05,
                        6.47187268e-04,
                        8.58846892e-05,
                        1.54437816e-04,
                        3.09995532e-04,
                    ],
                ]
            ),
        )


class TestDenoiseCovariance:
    def test_denoise_covariance(self, X):
        model = DenoiseCovariance()
        model.fit(X)
        assert model.covariance_.shape == (20, 20)
        np.testing.assert_almost_equal(
            model.covariance_,
            np.array(
                [
                    [
                        3.36851928e-04,
                        2.96226518e-04,
                        1.50198062e-04,
                        2.08290279e-04,
                        1.13739162e-04,
                        1.38929029e-04,
                        1.47089690e-04,
                        7.63976356e-05,
                        1.34906888e-04,
                        8.64503154e-05,
                        9.29280085e-05,
                        7.67552391e-05,
                        1.65072711e-04,
                        9.53629027e-05,
                        8.42142515e-05,
                        8.83014182e-05,
                        1.44224568e-04,
                        1.30072416e-04,
                        9.89320074e-05,
                        9.61903058e-05,
                    ],
                    [
                        2.96226518e-04,
                        1.39232325e-03,
                        2.45579004e-04,
                        3.78063001e-04,
                        1.74523560e-04,
                        2.24557031e-04,
                        2.38326670e-04,
                        8.35514734e-05,
                        2.15161188e-04,
                        1.09349052e-04,
                        9.07126468e-05,
                        7.45648626e-05,
                        2.66929104e-04,
                        1.23357760e-04,
                        8.78744674e-05,
                        1.10222956e-04,
                        2.66202857e-04,
                        1.82112331e-04,
                        1.38048025e-04,
                        1.45256569e-04,
                    ],
                    [
                        1.50198062e-04,
                        2.45579004e-04,
                        3.92897019e-04,
                        1.98280999e-04,
                        2.07537628e-04,
                        2.24324617e-04,
                        1.34888015e-04,
                        8.13929343e-05,
                        1.95397249e-04,
                        9.24523024e-05,
                        9.80095757e-05,
                        9.29191060e-05,
                        1.44936128e-04,
                        8.42082871e-05,
                        9.86673480e-05,
                        7.52104134e-05,
                        3.22814750e-04,
                        1.41321754e-04,
                        7.25487908e-05,
                        1.87824173e-04,
                    ],
                    [
                        2.08290279e-04,
                        3.78063001e-04,
                        1.98280999e-04,
                        6.15226996e-04,
                        1.54649017e-04,
                        1.87036328e-04,
                        1.72009700e-04,
                        7.23972102e-05,
                        1.74444085e-04,
                        8.93159085e-05,
                        8.24215017e-05,
                        7.09663079e-05,
                        1.91124114e-04,
                        9.53176738e-05,
                        8.00129317e-05,
                        8.55781295e-05,
                        2.33538344e-04,
                        1.43628436e-04,
                        1.00058528e-04,
                        1.32788276e-04,
                    ],
                    [
                        1.13739162e-04,
                        1.74523560e-04,
                        2.07537628e-04,
                        1.54649017e-04,
                        3.60718475e-04,
                        2.14761143e-04,
                        1.07228293e-04,
                        7.46064948e-05,
                        1.82701776e-04,
                        8.27526143e-05,
                        9.11192671e-05,
                        8.93139759e-05,
                        1.12874045e-04,
                        7.01009825e-05,
                        9.33018975e-05,
                        6.22398836e-05,
                        3.23536060e-04,
                        1.24634396e-04,
                        5.39791606e-05,
                        1.88167725e-04,
                    ],
                    [
                        1.38929029e-04,
                        2.24557031e-04,
                        2.24324617e-04,
                        1.87036328e-04,
                        2.14761143e-04,
                        4.82677024e-04,
                        1.26723573e-04,
                        7.92424146e-05,
                        1.97256707e-04,
                        8.98357948e-05,
                        9.54331535e-05,
                        9.23483364e-05,
                        1.34946289e-04,
                        7.89749328e-05,
                        9.75220775e-05,
                        7.00680866e-05,
                        3.39016709e-04,
                        1.37401444e-04,
                        6.50436667e-05,
                        1.95565165e-04,
                    ],
                    [
                        1.47089690e-04,
                        2.38326670e-04,
                        1.34888015e-04,
                        1.72009700e-04,
                        1.07228293e-04,
                        1.26723573e-04,
                        2.35179319e-04,
                        7.32368606e-05,
                        1.21784694e-04,
                        8.03593204e-05,
                        9.08794930e-05,
                        7.60678095e-05,
                        1.40971650e-04,
                        8.67740463e-05,
                        8.21603963e-05,
                        8.08178271e-05,
                        1.32957686e-04,
                        1.18063033e-04,
                        8.71253231e-05,
                        9.20552524e-05,
                    ],
                    [
                        7.63976356e-05,
                        8.35514734e-05,
                        8.13929343e-05,
                        7.23972102e-05,
                        7.46064948e-05,
                        7.92424146e-05,
                        7.32368606e-05,
                        1.30933719e-04,
                        7.70031820e-05,
                        6.86121671e-05,
                        9.48000690e-05,
                        7.97760291e-05,
                        8.19725634e-05,
                        7.17586448e-05,
                        8.24150242e-05,
                        6.93287520e-05,
                        6.50828795e-05,
                        8.95686733e-05,
                        6.50183655e-05,
                        6.61664443e-05,
                    ],
                    [
                        1.34906888e-04,
                        2.15161188e-04,
                        1.95397249e-04,
                        1.74444085e-04,
                        1.82701776e-04,
                        1.97256707e-04,
                        1.21784694e-04,
                        7.70031820e-05,
                        3.01178283e-04,
                        8.59083308e-05,
                        9.39448182e-05,
                        8.77779583e-05,
                        1.31266299e-04,
                        7.94129568e-05,
                        9.29019368e-05,
                        7.16021816e-05,
                        2.77624522e-04,
                        1.29328282e-04,
                        6.87910672e-05,
                        1.65188245e-04,
                    ],
                    [
                        8.64503154e-05,
                        1.09349052e-04,
                        9.24523024e-05,
                        8.93159085e-05,
                        8.27526143e-05,
                        8.98357948e-05,
                        8.03593204e-05,
                        6.86121671e-05,
                        8.59083308e-05,
                        1.34130222e-04,
                        9.01792425e-05,
                        7.63895291e-05,
                        8.96167327e-05,
                        7.12248755e-05,
                        7.95423176e-05,
                        6.80773836e-05,
                        8.50794113e-05,
                        9.21523583e-05,
                        6.54830927e-05,
                        7.31809234e-05,
                    ],
                    [
                        9.29280085e-05,
                        9.07126468e-05,
                        9.80095757e-05,
                        8.24215017e-05,
                        9.11192671e-05,
                        9.54331535e-05,
                        9.08794930e-05,
                        9.48000690e-05,
                        9.39448182e-05,
                        9.01792425e-05,
                        2.79158697e-04,
                        1.07124182e-04,
                        1.02013599e-04,
                        9.46677231e-05,
                        1.10215732e-04,
                        9.20305342e-05,
                        6.91080362e-05,
                        1.15540879e-04,
                        8.51865138e-05,
                        8.09055448e-05,
                    ],
                    [
                        7.67552391e-05,
                        7.45648626e-05,
                        9.29191060e-05,
                        7.09663079e-05,
                        8.93139759e-05,
                        9.23483364e-05,
                        7.60678095e-05,
                        7.97760291e-05,
                        8.77779583e-05,
                        7.63895291e-05,
                        1.07124182e-04,
                        1.86622434e-04,
                        8.45436625e-05,
                        7.80208736e-05,
                        9.37666936e-05,
                        7.54451764e-05,
                        8.32224749e-05,
                        9.88130858e-05,
                        6.83903510e-05,
                        8.02772266e-05,
                    ],
                    [
                        1.65072711e-04,
                        2.66929104e-04,
                        1.44936128e-04,
                        1.91124114e-04,
                        1.12874045e-04,
                        1.34946289e-04,
                        1.40971650e-04,
                        8.19725634e-05,
                        1.31266299e-04,
                        8.96167327e-05,
                        1.02013599e-04,
                        8.45436625e-05,
                        2.95295468e-04,
                        9.79660267e-05,
                        9.14132252e-05,
                        9.15146301e-05,
                        1.34612401e-04,
                        1.31135041e-04,
                        9.92336805e-05,
                        9.61695044e-05,
                    ],
                    [
                        9.53629027e-05,
                        1.23357760e-04,
                        8.42082871e-05,
                        9.53176738e-05,
                        7.01009825e-05,
                        7.89749328e-05,
                        8.67740463e-05,
                        7.17586448e-05,
                        7.94129568e-05,
                        7.12248755e-05,
                        9.46677231e-05,
                        7.80208736e-05,
                        9.79660267e-05,
                        1.38626742e-04,
                        8.16352365e-05,
                        7.44027005e-05,
                        5.66039607e-05,
                        9.52503995e-05,
                        7.39684821e-05,
                        6.04340756e-05,
                    ],
                    [
                        8.42142515e-05,
                        8.78744674e-05,
                        9.86673480e-05,
                        8.00129317e-05,
                        9.33018975e-05,
                        9.75220775e-05,
                        8.21603963e-05,
                        8.24150242e-05,
                        9.29019368e-05,
                        7.95423176e-05,
                        1.10215732e-04,
                        9.37666936e-05,
                        9.14132252e-05,
                        8.16352365e-05,
                        2.01688838e-04,
                        7.87627130e-05,
                        8.84370778e-05,
                        1.03743907e-04,
                        7.23425334e-05,
                        8.35502351e-05,
                    ],
                    [
                        8.83014182e-05,
                        1.10222956e-04,
                        7.52104134e-05,
                        8.55781295e-05,
                        6.22398836e-05,
                        7.00680866e-05,
                        8.08178271e-05,
                        6.93287520e-05,
                        7.16021816e-05,
                        6.80773836e-05,
                        9.20305342e-05,
                        7.54451764e-05,
                        9.15146301e-05,
                        7.44027005e-05,
                        7.87627130e-05,
                        1.36865583e-04,
                        4.34369257e-05,
                        8.99807179e-05,
                        7.11604921e-05,
                        5.34284074e-05,
                    ],
                    [
                        1.44224568e-04,
                        2.66202857e-04,
                        3.22814750e-04,
                        2.33538344e-04,
                        3.23536060e-04,
                        3.39016709e-04,
                        1.32957686e-04,
                        6.50828795e-05,
                        2.77624522e-04,
                        8.50794113e-05,
                        6.91080362e-05,
                        8.32224749e-05,
                        1.34612401e-04,
                        5.66039607e-05,
                        8.84370778e-05,
                        4.34369257e-05,
                        1.46834330e-03,
                        1.45571274e-04,
                        3.33006208e-05,
                        2.99086016e-04,
                    ],
                    [
                        1.30072416e-04,
                        1.82112331e-04,
                        1.41321754e-04,
                        1.43628436e-04,
                        1.24634396e-04,
                        1.37401444e-04,
                        1.18063033e-04,
                        8.95686733e-05,
                        1.29328282e-04,
                        9.21523583e-05,
                        1.15540879e-04,
                        9.88130858e-05,
                        1.31135041e-04,
                        9.52503995e-05,
                        1.03743907e-04,
                        8.99807179e-05,
                        1.45571274e-04,
                        2.64503039e-04,
                        8.85871195e-05,
                        1.10117345e-04,
                    ],
                    [
                        9.89320074e-05,
                        1.38048025e-04,
                        7.25487908e-05,
                        1.00058528e-04,
                        5.39791606e-05,
                        6.50436667e-05,
                        8.71253231e-05,
                        6.50183655e-05,
                        6.87910672e-05,
                        6.54830927e-05,
                        8.51865138e-05,
                        6.83903510e-05,
                        9.92336805e-05,
                        7.39684821e-05,
                        7.23425334e-05,
                        7.11604921e-05,
                        3.33006208e-05,
                        8.85871195e-05,
                        1.79815850e-04,
                        4.46914915e-05,
                    ],
                    [
                        9.61903058e-05,
                        1.45256569e-04,
                        1.87824173e-04,
                        1.32788276e-04,
                        1.88167725e-04,
                        1.95565165e-04,
                        9.20552524e-05,
                        6.61664443e-05,
                        1.65188245e-04,
                        7.31809234e-05,
                        8.09055448e-05,
                        8.02772266e-05,
                        9.61695044e-05,
                        6.04340756e-05,
                        8.35502351e-05,
                        5.34284074e-05,
                        2.99086016e-04,
                        1.10117345e-04,
                        4.46914915e-05,
                        3.08618732e-04,
                    ],
                ]
            ),
        )

    def test_metadata_routing(self, X, implied_vol):
        with config_context(enable_metadata_routing=True):
            model = DenoiseCovariance(
                covariance_estimator=ImpliedCovariance().set_fit_request(
                    implied_vol=True
                )
            )

            with pytest.raises(ValueError):
                model.fit(X)

            model.fit(X, implied_vol=implied_vol)

        # noinspection PyUnresolvedReferences
        assert model.covariance_estimator_.r2_scores_.shape == (20,)
        assert model.covariance_.shape == (20, 20)


class TestDetoneCovariance:
    @pytest.mark.filterwarnings("ignore:The covariance matrix is not positive definite")
    def test_detone_covariance(self, X):
        model = DetoneCovariance(covariance_estimator=DenoiseCovariance())
        model.fit(X)
        assert model.covariance_.shape == (20, 20)
        np.testing.assert_almost_equal(
            model.covariance_,
            np.array(
                [
                    [
                        3.36851928e-04,
                        1.22239534e-04,
                        -2.51729943e-05,
                        6.40304437e-05,
                        -5.43665457e-05,
                        -3.92490108e-05,
                        3.07729776e-05,
                        -3.12917840e-05,
                        -2.57022161e-05,
                        -2.28902372e-05,
                        -4.61126564e-05,
                        -4.69319678e-05,
                        3.81450580e-05,
                        -8.41760137e-06,
                        -4.44218474e-05,
                        -1.00452471e-05,
                        -6.29373981e-05,
                        -1.94435159e-05,
                        7.51170890e-06,
                        -5.49722926e-05,
                    ],
                    [
                        1.22239534e-04,
                        1.39232325e-03,
                        3.94800954e-06,
                        1.77135063e-04,
                        -6.04254036e-05,
                        -2.30678956e-05,
                        7.19231331e-05,
                        -8.59011703e-05,
                        -8.08965599e-06,
                        -5.93683128e-05,
                        -1.25612847e-04,
                        -1.17383553e-04,
                        8.39797816e-05,
                        -3.95334870e-05,
                        -1.11422525e-04,
                        -4.43197160e-05,
                        -1.47383909e-05,
                        -4.21406248e-05,
                        -2.46312269e-06,
                        -6.61050102e-05,
                    ],
                    [
                        -2.51729943e-05,
                        3.94800954e-06,
                        3.92897019e-04,
                        1.35967345e-05,
                        7.72347637e-05,
                        7.14886200e-05,
                        -2.45905134e-05,
                        -4.57502111e-05,
                        5.40771180e-05,
                        -3.68147789e-05,
                        -6.58630830e-05,
                        -4.38333435e-05,
                        -3.48438408e-05,
                        -5.52640492e-05,
                        -4.55760900e-05,
                        -5.69132845e-05,
                        1.67081908e-04,
                        -3.36571751e-05,
                        -5.75028524e-05,
                        7.30665182e-05,
                    ],
                    [
                        6.40304437e-05,
                        1.77135063e-04,
                        1.35967345e-05,
                        6.15226996e-04,
                        -2.17902572e-05,
                        -1.71606749e-06,
                        3.51314020e-05,
                        -5.97700875e-05,
                        3.85378371e-06,
                        -4.28626999e-05,
                        -8.70525642e-05,
                        -7.77986753e-05,
                        3.99732962e-05,
                        -3.48472491e-05,
                        -7.47966925e-05,
                        -3.78642120e-05,
                        2.12907197e-05,
                        -3.29669876e-05,
                        -1.38484438e-05,
                        -2.56695263e-05,
                    ],
                    [
                        -5.43665457e-05,
                        -6.04254036e-05,
                        7.72347637e-05,
                        -2.17902572e-05,
                        3.60718475e-04,
                        8.56857478e-05,
                        -4.31633197e-05,
                        -3.38777628e-05,
                        6.25403180e-05,
                        -2.92958584e-05,
                        -4.81446455e-05,
                        -2.50007039e-05,
                        -5.73210843e-05,
                        -5.44389997e-05,
                        -2.82099848e-05,
                        -5.52203646e-05,
                        1.92355811e-04,
                        -2.93230714e-05,
                        -6.44919191e-05,
                        9.63357501e-05,
                    ],
                    [
                        -3.92490108e-05,
                        -2.30678956e-05,
                        7.14886200e-05,
                        -1.71606749e-06,
                        8.56857478e-05,
                        4.82677024e-04,
                        -3.45274644e-05,
                        -4.39379623e-05,
                        5.62129045e-05,
                        -3.65134296e-05,
                        -6.24728514e-05,
                        -3.92971503e-05,
                        -4.67494624e-05,
                        -5.81188486e-05,
                        -4.17290158e-05,
                        -5.92555776e-05,
                        1.79228420e-04,
                        -3.51283361e-05,
                        -6.29126384e-05,
                        8.19963262e-05,
                    ],
                    [
                        3.07729776e-05,
                        7.19231331e-05,
                        -2.45905134e-05,
                        3.51314020e-05,
                        -4.31633197e-05,
                        -3.45274644e-05,
                        2.35179319e-04,
                        -2.13242649e-05,
                        -2.38024898e-05,
                        -1.67810018e-05,
                        -3.13668085e-05,
                        -3.22039735e-05,
                        2.17449166e-05,
                        -6.10970962e-06,
                        -3.08047055e-05,
                        -7.01285772e-06,
                        -5.53994219e-05,
                        -1.65212276e-05,
                        3.94602035e-06,
                        -4.28817059e-05,
                    ],
                    [
                        -3.12917840e-05,
                        -8.59011703e-05,
                        -4.57502111e-05,
                        -5.97700875e-05,
                        -3.38777628e-05,
                        -4.39379623e-05,
                        -2.13242649e-05,
                        1.30933719e-04,
                        -3.64571612e-05,
                        9.56463625e-06,
                        2.87804456e-05,
                        2.21358976e-05,
                        -2.13389466e-05,
                        1.40624942e-05,
                        2.04775615e-05,
                        1.59391348e-05,
                        -8.34376829e-05,
                        -1.85094324e-06,
                        6.98892234e-06,
                        -2.93823005e-05,
                    ],
                    [
                        -2.57022161e-05,
                        -8.08965599e-06,
                        5.40771180e-05,
                        3.85378371e-06,
                        6.25403180e-05,
                        5.62129045e-05,
                        -2.38024898e-05,
                        -3.64571612e-05,
                        3.01178283e-04,
                        -3.00951769e-05,
                        -5.24470402e-05,
                        -3.43843711e-05,
                        -3.26315812e-05,
                        -4.54309924e-05,
                        -3.61009839e-05,
                        -4.66241183e-05,
                        1.33345492e-04,
                        -2.88047318e-05,
                        -4.84167784e-05,
                        5.95052975e-05,
                    ],
                    [
                        -2.28902372e-05,
                        -5.93683128e-05,
                        -3.68147789e-05,
                        -4.28626999e-05,
                        -2.92958584e-05,
                        -3.65134296e-05,
                        -1.67810018e-05,
                        9.56463625e-06,
                        -3.00951769e-05,
                        1.34130222e-04,
                        1.44175319e-05,
                        1.02969768e-05,
                        -1.67633981e-05,
                        6.75021457e-06,
                        9.03577257e-06,
                        8.08938690e-06,
                        -6.54926892e-05,
                        -6.36915085e-06,
                        2.46107865e-06,
                        -2.58083144e-05,
                    ],
                    [
                        -4.61126564e-05,
                        -1.25612847e-04,
                        -6.58630830e-05,
                        -8.70525642e-05,
                        -4.81446455e-05,
                        -6.24728514e-05,
                        -3.13668085e-05,
                        2.87804456e-05,
                        -5.24470402e-05,
                        1.44175319e-05,
                        2.79158697e-04,
                        3.31287044e-05,
                        -3.15174078e-05,
                        2.04813636e-05,
                        3.07365146e-05,
                        2.33433184e-05,
                        -1.18756276e-04,
                        -1.96869455e-06,
                        1.04162725e-05,
                        -4.15805671e-05,
                    ],
                    [
                        -4.69319678e-05,
                        -1.17383553e-04,
                        -4.38333435e-05,
                        -7.77986753e-05,
                        -2.50007039e-05,
                        -3.92971503e-05,
                        -3.22039735e-05,
                        2.21358976e-05,
                        -3.43843711e-05,
                        1.02969768e-05,
                        3.31287044e-05,
                        1.86622434e-04,
                        -3.43159667e-05,
                        1.16405319e-05,
                        2.51981293e-05,
                        1.39835112e-05,
                        -7.24910665e-05,
                        -3.33153611e-06,
                        1.18759135e-06,
                        -1.99801411e-05,
                    ],
                    [
                        3.81450580e-05,
                        8.39797816e-05,
                        -3.48438408e-05,
                        3.99732962e-05,
                        -5.73210843e-05,
                        -4.67494624e-05,
                        2.17449166e-05,
                        -2.13389466e-05,
                        -3.26315812e-05,
                        -1.67633981e-05,
                        -3.15174078e-05,
                        -3.43159667e-05,
                        2.95295468e-04,
                        -2.65653518e-06,
                        -3.25363612e-05,
                        -3.58266934e-06,
                        -7.93252454e-05,
                        -1.67827839e-05,
                        9.32366908e-06,
                        -5.66293897e-05,
                    ],
                    [
                        -8.41760137e-06,
                        -3.95334870e-05,
                        -5.52640492e-05,
                        -3.48472491e-05,
                        -5.44389997e-05,
                        -5.81188486e-05,
                        -6.10970962e-06,
                        1.40624942e-05,
                        -4.54309924e-05,
                        6.75021457e-06,
                        2.04813636e-05,
                        1.16405319e-05,
                        -2.65653518e-06,
                        1.38626742e-04,
                        1.11585081e-05,
                        1.85174888e-05,
                        -1.11488724e-04,
                        -2.45434795e-06,
                        1.57977325e-05,
                        -5.02422150e-05,
                    ],
                    [
                        -4.44218474e-05,
                        -1.11422525e-04,
                        -4.55760900e-05,
                        -7.47966925e-05,
                        -2.82099848e-05,
                        -4.17290158e-05,
                        -3.08047055e-05,
                        2.04775615e-05,
                        -3.61009839e-05,
                        9.03577257e-06,
                        3.07365146e-05,
                        2.51981293e-05,
                        -3.25363612e-05,
                        1.11585081e-05,
                        2.01688838e-04,
                        1.34432264e-05,
                        -7.63501717e-05,
                        -4.49766645e-06,
                        1.56850630e-06,
                        -2.31770766e-05,
                    ],
                    [
                        -1.00452471e-05,
                        -4.43197160e-05,
                        -5.69132845e-05,
                        -3.78642120e-05,
                        -5.52203646e-05,
                        -5.92555776e-05,
                        -7.01285772e-06,
                        1.59391348e-05,
                        -4.66241183e-05,
                        8.08938690e-06,
                        2.33433184e-05,
                        1.39835112e-05,
                        -3.58266934e-06,
                        1.85174888e-05,
                        1.34432264e-05,
                        1.36865583e-04,
                        -1.14314370e-04,
                        -1.47277391e-06,
                        1.67644461e-05,
                        -5.08160573e-05,
                    ],
                    [
                        -6.29373981e-05,
                        -1.47383909e-05,
                        1.67081908e-04,
                        2.12907197e-05,
                        1.92355811e-04,
                        1.79228420e-04,
                        -5.53994219e-05,
                        -8.34376829e-05,
                        1.33345492e-04,
                        -6.54926892e-05,
                        -1.18756276e-04,
                        -7.24910665e-05,
                        -7.93252454e-05,
                        -1.11488724e-04,
                        -7.63501717e-05,
                        -1.14314370e-04,
                        1.46834330e-03,
                        -5.58396617e-05,
                        -1.19303810e-04,
                        1.82792997e-04,
                    ],
                    [
                        -1.94435159e-05,
                        -4.21406248e-05,
                        -3.36571751e-05,
                        -3.29669876e-05,
                        -2.93230714e-05,
                        -3.51283361e-05,
                        -1.65212276e-05,
                        -1.85094324e-06,
                        -2.88047318e-05,
                        -6.36915085e-06,
                        -1.96869455e-06,
                        -3.33153611e-06,
                        -1.67827839e-05,
                        -2.45434795e-06,
                        -4.49766645e-06,
                        -1.47277391e-06,
                        -5.58396617e-05,
                        2.64503039e-04,
                        -4.46027806e-06,
                        -2.62648868e-05,
                    ],
                    [
                        7.51170890e-06,
                        -2.46312269e-06,
                        -5.75028524e-05,
                        -1.38484438e-05,
                        -6.44919191e-05,
                        -6.29126384e-05,
                        3.94602035e-06,
                        6.98892234e-06,
                        -4.84167784e-05,
                        2.46107865e-06,
                        1.04162725e-05,
                        1.18759135e-06,
                        9.32366908e-06,
                        1.57977325e-05,
                        1.56850630e-06,
                        1.67644461e-05,
                        -1.19303810e-04,
                        -4.46027806e-06,
                        1.79815850e-04,
                        -6.07651926e-05,
                    ],
                    [
                        -5.49722926e-05,
                        -6.61050102e-05,
                        7.30665182e-05,
                        -2.56695263e-05,
                        9.63357501e-05,
                        8.19963262e-05,
                        -4.28817059e-05,
                        -2.93823005e-05,
                        5.95052975e-05,
                        -2.58083144e-05,
                        -4.15805671e-05,
                        -1.99801411e-05,
                        -5.66293897e-05,
                        -5.02422150e-05,
                        -2.31770766e-05,
                        -5.08160573e-05,
                        1.82792997e-04,
                        -2.62648868e-05,
                        -6.07651926e-05,
                        3.08618732e-04,
                    ],
                ]
            ),
        )

    @pytest.mark.filterwarnings("ignore:The covariance matrix is not positive definite")
    def test_metadata_routing(self, X, implied_vol):
        with config_context(enable_metadata_routing=True):
            model = DetoneCovariance(
                covariance_estimator=ImpliedCovariance().set_fit_request(
                    implied_vol=True
                )
            )

            with pytest.raises(ValueError):
                model.fit(X)

            model.fit(X, implied_vol=implied_vol)

        # noinspection PyUnresolvedReferences
        assert model.covariance_estimator_.r2_scores_.shape == (20,)
        assert model.covariance_.shape == (20, 20)


class TestGerberCovariance:
    def test_gerber_covariance(self, X):
        model = GerberCovariance()
        model.fit(X)
        assert model.covariance_.shape == (20, 20)
        np.testing.assert_almost_equal(
            model.covariance_,
            np.array(
                [
                    [
                        3.36703077e-04,
                        1.81470040e-04,
                        7.59836524e-05,
                        1.05986524e-04,
                        5.38990581e-05,
                        7.01531478e-05,
                        6.88072413e-05,
                        3.45288575e-05,
                        7.36139822e-05,
                        3.62682022e-05,
                        4.60448294e-05,
                        3.76076861e-05,
                        1.30174918e-04,
                        4.35810681e-05,
                        4.35878478e-05,
                        4.13366783e-05,
                        5.72239483e-05,
                        6.35051726e-05,
                        4.33204139e-05,
                        5.01833370e-05,
                    ],
                    [
                        1.81470040e-04,
                        1.39170799e-03,
                        1.34207540e-04,
                        1.68255311e-04,
                        1.05754595e-04,
                        1.19198038e-04,
                        1.09290158e-04,
                        4.54076889e-05,
                        1.12211113e-04,
                        3.98142999e-05,
                        7.08143043e-05,
                        5.53351457e-05,
                        1.84539745e-04,
                        4.96277564e-05,
                        6.76546794e-05,
                        4.67703853e-05,
                        1.69190997e-04,
                        8.81689798e-05,
                        5.68341537e-05,
                        7.63527912e-05,
                    ],
                    [
                        7.59836524e-05,
                        1.34207540e-04,
                        3.92723401e-04,
                        1.14606785e-04,
                        1.04445805e-04,
                        1.32529096e-04,
                        6.87762105e-05,
                        3.69424236e-05,
                        2.20632110e-04,
                        3.95825565e-05,
                        4.62825384e-05,
                        4.42635283e-05,
                        7.51317241e-05,
                        2.77847896e-05,
                        4.91743749e-05,
                        2.92864720e-05,
                        1.41060091e-04,
                        7.02419956e-05,
                        3.35650483e-05,
                        9.68212858e-05,
                    ],
                    [
                        1.05986524e-04,
                        1.68255311e-04,
                        1.14606785e-04,
                        6.14955132e-04,
                        7.73131440e-05,
                        9.28499075e-05,
                        1.19016317e-04,
                        3.73282731e-05,
                        1.03052862e-04,
                        3.47108573e-05,
                        4.05860269e-05,
                        3.53366049e-05,
                        8.89957914e-05,
                        4.09540246e-05,
                        3.72838274e-05,
                        4.15144389e-05,
                        1.06372387e-04,
                        6.33629979e-05,
                        6.47343615e-05,
                        7.04645924e-05,
                    ],
                    [
                        5.38990581e-05,
                        1.05754595e-04,
                        1.04445805e-04,
                        7.73131440e-05,
                        3.60559076e-04,
                        1.10987979e-04,
                        5.23278711e-05,
                        3.70567279e-05,
                        9.88829546e-05,
                        3.67421001e-05,
                        4.83494072e-05,
                        4.25613633e-05,
                        5.84255727e-05,
                        2.86563680e-05,
                        4.55825214e-05,
                        3.04138518e-05,
                        1.95853228e-04,
                        4.99804875e-05,
                        3.00191782e-05,
                        1.83275668e-04,
                    ],
                    [
                        7.01531478e-05,
                        1.19198038e-04,
                        1.32529096e-04,
                        9.28499075e-05,
                        1.10987979e-04,
                        4.82463733e-04,
                        5.22422547e-05,
                        3.76340807e-05,
                        1.25690315e-04,
                        4.45380574e-05,
                        4.61677378e-05,
                        4.03358586e-05,
                        6.17926931e-05,
                        3.51423104e-05,
                        4.55685241e-05,
                        3.48296080e-05,
                        1.41584424e-04,
                        5.41137657e-05,
                        3.41679407e-05,
                        1.04702087e-04,
                    ],
                    [
                        6.88072413e-05,
                        1.09290158e-04,
                        6.87762105e-05,
                        1.19016317e-04,
                        5.23278711e-05,
                        5.22422547e-05,
                        2.35075395e-04,
                        3.75539161e-05,
                        6.83362229e-05,
                        3.91029391e-05,
                        4.43777965e-05,
                        3.54419669e-05,
                        7.65733344e-05,
                        4.52062642e-05,
                        4.01452839e-05,
                        4.00436075e-05,
                        4.51013591e-05,
                        5.61126261e-05,
                        5.22382183e-05,
                        4.62486116e-05,
                    ],
                    [
                        3.45288575e-05,
                        4.54076889e-05,
                        3.69424236e-05,
                        3.73282731e-05,
                        3.70567279e-05,
                        3.76340807e-05,
                        3.75539161e-05,
                        1.30875861e-04,
                        3.86774524e-05,
                        3.54273626e-05,
                        6.16449758e-05,
                        5.28249301e-05,
                        4.11256085e-05,
                        3.90767376e-05,
                        5.01740370e-05,
                        3.96273127e-05,
                        1.91116190e-05,
                        4.76657269e-05,
                        3.19978898e-05,
                        3.27272466e-05,
                    ],
                    [
                        7.36139822e-05,
                        1.12211113e-04,
                        2.20632110e-04,
                        1.03052862e-04,
                        9.88829546e-05,
                        1.25690315e-04,
                        6.83362229e-05,
                        3.86774524e-05,
                        3.01045195e-04,
                        4.43774453e-05,
                        4.71163761e-05,
                        4.61246030e-05,
                        7.19939345e-05,
                        3.49517948e-05,
                        4.97524096e-05,
                        3.50128202e-05,
                        1.13497378e-04,
                        6.76869955e-05,
                        3.59631838e-05,
                        9.08519555e-05,
                    ],
                    [
                        3.62682022e-05,
                        3.98142999e-05,
                        3.95825565e-05,
                        3.47108573e-05,
                        3.67421001e-05,
                        4.45380574e-05,
                        3.91029391e-05,
                        3.54273626e-05,
                        4.43774453e-05,
                        1.34070951e-04,
                        3.45613759e-05,
                        3.50205132e-05,
                        4.37540357e-05,
                        6.29891715e-05,
                        3.44150890e-05,
                        5.23641910e-05,
                        2.21257097e-05,
                        3.74598868e-05,
                        3.59509900e-05,
                        3.54090056e-05,
                    ],
                    [
                        4.60448294e-05,
                        7.08143043e-05,
                        4.62825384e-05,
                        4.05860269e-05,
                        4.83494072e-05,
                        4.61677378e-05,
                        4.43777965e-05,
                        6.16449758e-05,
                        4.71163761e-05,
                        3.45613759e-05,
                        2.79035339e-04,
                        7.41294515e-05,
                        5.92107005e-05,
                        3.89723719e-05,
                        7.66169640e-05,
                        3.83669659e-05,
                        3.67527225e-05,
                        6.48890299e-05,
                        3.44648536e-05,
                        4.35071673e-05,
                    ],
                    [
                        3.76076861e-05,
                        5.53351457e-05,
                        4.42635283e-05,
                        3.53366049e-05,
                        4.25613633e-05,
                        4.03358586e-05,
                        3.54419669e-05,
                        5.28249301e-05,
                        4.61246030e-05,
                        3.50205132e-05,
                        7.41294515e-05,
                        1.86539967e-04,
                        4.57491397e-05,
                        3.70314458e-05,
                        6.94746180e-05,
                        3.58022460e-05,
                        2.84337829e-05,
                        5.19431691e-05,
                        2.97677998e-05,
                        3.88554921e-05,
                    ],
                    [
                        1.30174918e-04,
                        1.84539745e-04,
                        7.51317241e-05,
                        8.89957914e-05,
                        5.84255727e-05,
                        6.17926931e-05,
                        7.65733344e-05,
                        4.11256085e-05,
                        7.19939345e-05,
                        4.37540357e-05,
                        5.92107005e-05,
                        4.57491397e-05,
                        2.95164979e-04,
                        5.12419649e-05,
                        4.56307197e-05,
                        4.57356990e-05,
                        4.59109184e-05,
                        6.68998295e-05,
                        4.88533281e-05,
                        4.96000670e-05,
                    ],
                    [
                        4.35810681e-05,
                        4.96277564e-05,
                        2.77847896e-05,
                        4.09540246e-05,
                        2.86563680e-05,
                        3.51423104e-05,
                        4.52062642e-05,
                        3.90767376e-05,
                        3.49517948e-05,
                        6.29891715e-05,
                        3.89723719e-05,
                        3.70314458e-05,
                        5.12419649e-05,
                        1.38565484e-04,
                        3.53558945e-05,
                        5.61624305e-05,
                        9.06199705e-06,
                        3.82804367e-05,
                        4.29461062e-05,
                        3.13614916e-05,
                    ],
                    [
                        4.35878478e-05,
                        6.76546794e-05,
                        4.91743749e-05,
                        3.72838274e-05,
                        4.55825214e-05,
                        4.55685241e-05,
                        4.01452839e-05,
                        5.01740370e-05,
                        4.97524096e-05,
                        3.44150890e-05,
                        7.66169640e-05,
                        6.94746180e-05,
                        4.56307197e-05,
                        3.53558945e-05,
                        2.01599714e-04,
                        3.58784012e-05,
                        4.27462949e-05,
                        5.49966532e-05,
                        3.10333906e-05,
                        3.83660213e-05,
                    ],
                    [
                        4.13366783e-05,
                        4.67703853e-05,
                        2.92864720e-05,
                        4.15144389e-05,
                        3.04138518e-05,
                        3.48296080e-05,
                        4.00436075e-05,
                        3.96273127e-05,
                        3.50128202e-05,
                        5.23641910e-05,
                        3.83669659e-05,
                        3.58022460e-05,
                        4.57356990e-05,
                        5.61624305e-05,
                        3.58784012e-05,
                        1.36805103e-04,
                        2.05895598e-05,
                        3.78898256e-05,
                        4.26335672e-05,
                        2.99028382e-05,
                    ],
                    [
                        5.72239483e-05,
                        1.69190997e-04,
                        1.41060091e-04,
                        1.06372387e-04,
                        1.95853228e-04,
                        1.41584424e-04,
                        4.51013591e-05,
                        1.91116190e-05,
                        1.13497378e-04,
                        2.21257097e-05,
                        3.67527225e-05,
                        2.84337829e-05,
                        4.59109184e-05,
                        9.06199705e-06,
                        4.27462949e-05,
                        2.05895598e-05,
                        1.46769445e-03,
                        3.95276852e-05,
                        1.97781101e-05,
                        1.82864071e-04,
                    ],
                    [
                        6.35051726e-05,
                        8.81689798e-05,
                        7.02419956e-05,
                        6.33629979e-05,
                        4.99804875e-05,
                        5.41137657e-05,
                        5.61126261e-05,
                        4.76657269e-05,
                        6.76869955e-05,
                        3.74598868e-05,
                        6.48890299e-05,
                        5.19431691e-05,
                        6.68998295e-05,
                        3.82804367e-05,
                        5.49966532e-05,
                        3.78898256e-05,
                        3.95276852e-05,
                        2.64386157e-04,
                        4.01486856e-05,
                        4.94351421e-05,
                    ],
                    [
                        4.33204139e-05,
                        5.68341537e-05,
                        3.35650483e-05,
                        6.47343615e-05,
                        3.00191782e-05,
                        3.41679407e-05,
                        5.22382183e-05,
                        3.19978898e-05,
                        3.59631838e-05,
                        3.59509900e-05,
                        3.44648536e-05,
                        2.97677998e-05,
                        4.88533281e-05,
                        4.29461062e-05,
                        3.10333906e-05,
                        4.26335672e-05,
                        1.97781101e-05,
                        4.01486856e-05,
                        1.79736391e-04,
                        3.08937385e-05,
                    ],
                    [
                        5.01833370e-05,
                        7.63527912e-05,
                        9.68212858e-05,
                        7.04645924e-05,
                        1.83275668e-04,
                        1.04702087e-04,
                        4.62486116e-05,
                        3.27272466e-05,
                        9.08519555e-05,
                        3.54090056e-05,
                        4.35071673e-05,
                        3.88554921e-05,
                        4.96000670e-05,
                        3.13614916e-05,
                        3.83660213e-05,
                        2.99028382e-05,
                        1.82864071e-04,
                        4.94351421e-05,
                        3.08937385e-05,
                        3.08482356e-04,
                    ],
                ]
            ),
        )

        model = GerberCovariance(psd_variant=False)
        model.fit(X)
        assert model.covariance_.shape == (20, 20)
        np.testing.assert_almost_equal(
            model.covariance_,
            np.array(
                [
                    [
                        3.36703077e-04,
                        2.59738713e-04,
                        1.09491712e-04,
                        1.55055267e-04,
                        7.93229690e-05,
                        1.02204657e-04,
                        9.85410831e-05,
                        5.03578573e-05,
                        1.05811606e-04,
                        5.33410851e-05,
                        6.79721737e-05,
                        5.52535719e-05,
                        1.75484641e-04,
                        6.31818912e-05,
                        6.32229175e-05,
                        5.98567552e-05,
                        8.33370026e-05,
                        9.25241741e-05,
                        6.38965633e-05,
                        7.29294460e-05,
                    ],
                    [
                        2.59738713e-04,
                        1.39170799e-03,
                        1.93141599e-04,
                        2.45069412e-04,
                        1.56830277e-04,
                        1.76506484e-04,
                        1.59306320e-04,
                        6.72125362e-05,
                        1.64200645e-04,
                        5.91862429e-05,
                        1.04266940e-04,
                        8.11006382e-05,
                        2.62618999e-04,
                        7.43969678e-05,
                        9.99920176e-05,
                        6.86271578e-05,
                        2.46553544e-04,
                        1.29907822e-04,
                        8.45689814e-05,
                        1.12013863e-04,
                    ],
                    [
                        1.09491712e-04,
                        1.93141599e-04,
                        3.92723401e-04,
                        1.65222324e-04,
                        1.51365547e-04,
                        1.89240176e-04,
                        9.84226855e-05,
                        5.34565922e-05,
                        2.67504262e-04,
                        5.74749428e-05,
                        6.75803327e-05,
                        6.43590129e-05,
                        1.07204217e-04,
                        4.03948571e-05,
                        7.06858655e-05,
                        4.20282695e-05,
                        2.03530342e-04,
                        1.01799618e-04,
                        4.94055789e-05,
                        1.37587519e-04,
                    ],
                    [
                        1.55055267e-04,
                        2.45069412e-04,
                        1.65222324e-04,
                        6.14955132e-04,
                        1.13980424e-04,
                        1.37661253e-04,
                        1.68020077e-04,
                        5.41599308e-05,
                        1.48673817e-04,
                        5.13991467e-05,
                        5.96019468e-05,
                        5.17195819e-05,
                        1.28600248e-04,
                        6.05987952e-05,
                        5.47208457e-05,
                        6.05633872e-05,
                        1.55444229e-04,
                        9.36385172e-05,
                        9.41889951e-05,
                        1.02646063e-04,
                    ],
                    [
                        7.93229690e-05,
                        1.56830277e-04,
                        1.51365547e-04,
                        1.13980424e-04,
                        3.60559076e-04,
                        1.60265421e-04,
                        7.67878568e-05,
                        5.40312628e-05,
                        1.42498441e-04,
                        5.40018149e-05,
                        7.16081638e-05,
                        6.23932809e-05,
                        8.44003007e-05,
                        4.28562269e-05,
                        6.70550680e-05,
                        4.40962221e-05,
                        2.77273200e-04,
                        7.36769251e-05,
                        4.43110756e-05,
                        2.33878149e-04,
                    ],
                    [
                        1.02204657e-04,
                        1.76506484e-04,
                        1.89240176e-04,
                        1.37661253e-04,
                        1.60265421e-04,
                        4.82463733e-04,
                        7.61780147e-05,
                        5.47806180e-05,
                        1.75888378e-04,
                        6.55061369e-05,
                        6.86660445e-05,
                        5.91264647e-05,
                        8.92713011e-05,
                        5.19359596e-05,
                        6.63410394e-05,
                        5.08759777e-05,
                        2.04841692e-04,
                        8.00058097e-05,
                        5.07106300e-05,
                        1.48126536e-04,
                    ],
                    [
                        9.85410831e-05,
                        1.59306320e-04,
                        9.84226855e-05,
                        1.68020077e-04,
                        7.67878568e-05,
                        7.61780147e-05,
                        2.35075395e-04,
                        5.36004671e-05,
                        9.77484659e-05,
                        5.64307400e-05,
                        6.48427374e-05,
                        5.13789050e-05,
                        1.09451502e-04,
                        6.54481924e-05,
                        5.86303366e-05,
                        5.78621403e-05,
                        6.49949811e-05,
                        8.06056256e-05,
                        7.45225568e-05,
                        6.66373556e-05,
                    ],
                    [
                        5.03578573e-05,
                        6.72125362e-05,
                        5.34565922e-05,
                        5.41599308e-05,
                        5.40312628e-05,
                        5.47806180e-05,
                        5.36004671e-05,
                        1.30875861e-04,
                        5.60158938e-05,
                        5.08996106e-05,
                        8.69226360e-05,
                        7.28345529e-05,
                        5.87856832e-05,
                        5.49263894e-05,
                        7.11018842e-05,
                        5.61261989e-05,
                        2.80771213e-05,
                        6.82970678e-05,
                        4.66172115e-05,
                        4.80990329e-05,
                    ],
                    [
                        1.05811606e-04,
                        1.64200645e-04,
                        2.67504262e-04,
                        1.48673817e-04,
                        1.42498441e-04,
                        1.75888378e-04,
                        9.77484659e-05,
                        5.60158938e-05,
                        3.01045195e-04,
                        6.40428222e-05,
                        6.91850573e-05,
                        6.61254393e-05,
                        1.01709699e-04,
                        5.01359513e-05,
                        7.19511311e-05,
                        4.99441816e-05,
                        1.64485204e-04,
                        9.78971860e-05,
                        5.25376833e-05,
                        1.29197251e-04,
                    ],
                    [
                        5.33410851e-05,
                        5.91862429e-05,
                        5.74749428e-05,
                        5.13991467e-05,
                        5.40018149e-05,
                        6.55061369e-05,
                        5.64307400e-05,
                        5.08996106e-05,
                        6.40428222e-05,
                        1.34070951e-04,
                        5.09018115e-05,
                        5.08108101e-05,
                        6.26558952e-05,
                        8.39118142e-05,
                        5.03431534e-05,
                        7.17213253e-05,
                        3.24637323e-05,
                        5.48727240e-05,
                        5.19446849e-05,
                        5.15497127e-05,
                    ],
                    [
                        6.79721737e-05,
                        1.04266940e-04,
                        6.75803327e-05,
                        5.96019468e-05,
                        7.16081638e-05,
                        6.86660445e-05,
                        6.48427374e-05,
                        8.69226360e-05,
                        6.91850573e-05,
                        5.09018115e-05,
                        2.79035339e-04,
                        1.04433688e-04,
                        8.60347477e-05,
                        5.65544589e-05,
                        1.07124591e-04,
                        5.58498933e-05,
                        5.48734840e-05,
                        9.31736469e-05,
                        5.04125987e-05,
                        6.39314297e-05,
                    ],
                    [
                        5.52535719e-05,
                        8.11006382e-05,
                        6.43590129e-05,
                        5.17195819e-05,
                        6.23932809e-05,
                        5.91264647e-05,
                        5.13789050e-05,
                        7.28345529e-05,
                        6.61254393e-05,
                        5.08108101e-05,
                        1.04433688e-04,
                        1.86539967e-04,
                        6.55564991e-05,
                        5.28600255e-05,
                        9.65218962e-05,
                        5.14681100e-05,
                        4.09363178e-05,
                        7.48882632e-05,
                        4.35332486e-05,
                        5.66260792e-05,
                    ],
                    [
                        1.75484641e-04,
                        2.62618999e-04,
                        1.07204217e-04,
                        1.28600248e-04,
                        8.44003007e-05,
                        8.92713011e-05,
                        1.09451502e-04,
                        5.87856832e-05,
                        1.01709699e-04,
                        6.26558952e-05,
                        8.60347477e-05,
                        6.55564991e-05,
                        2.95164979e-04,
                        7.35409978e-05,
                        6.61064920e-05,
                        6.52042832e-05,
                        6.67061616e-05,
                        9.57482609e-05,
                        7.10895859e-05,
                        7.09214267e-05,
                    ],
                    [
                        6.31818912e-05,
                        7.43969678e-05,
                        4.03948571e-05,
                        6.05987952e-05,
                        4.28562269e-05,
                        5.19359596e-05,
                        6.54481924e-05,
                        5.49263894e-05,
                        5.01359513e-05,
                        8.39118142e-05,
                        5.65544589e-05,
                        5.28600255e-05,
                        7.35409978e-05,
                        1.38565484e-04,
                        5.10231684e-05,
                        7.65227006e-05,
                        1.33530078e-05,
                        5.54946405e-05,
                        6.18057249e-05,
                        4.59275123e-05,
                    ],
                    [
                        6.32229175e-05,
                        9.99920176e-05,
                        7.06858655e-05,
                        5.47208457e-05,
                        6.70550680e-05,
                        6.63410394e-05,
                        5.86303366e-05,
                        7.11018842e-05,
                        7.19511311e-05,
                        5.03431534e-05,
                        1.07124591e-04,
                        9.65218962e-05,
                        6.61064920e-05,
                        5.10231684e-05,
                        2.01599714e-04,
                        5.18398260e-05,
                        6.24021345e-05,
                        8.01716755e-05,
                        4.58819945e-05,
                        5.57058604e-05,
                    ],
                    [
                        5.98567552e-05,
                        6.86271578e-05,
                        4.20282695e-05,
                        6.05633872e-05,
                        4.40962221e-05,
                        5.08759777e-05,
                        5.78621403e-05,
                        5.61261989e-05,
                        4.99441816e-05,
                        7.17213253e-05,
                        5.58498933e-05,
                        5.14681100e-05,
                        6.52042832e-05,
                        7.65227006e-05,
                        5.18398260e-05,
                        1.36805103e-04,
                        2.99624528e-05,
                        5.49979716e-05,
                        6.12954234e-05,
                        4.31980769e-05,
                    ],
                    [
                        8.33370026e-05,
                        2.46553544e-04,
                        2.03530342e-04,
                        1.55444229e-04,
                        2.77273200e-04,
                        2.04841692e-04,
                        6.49949811e-05,
                        2.80771213e-05,
                        1.64485204e-04,
                        3.24637323e-05,
                        5.48734840e-05,
                        4.09363178e-05,
                        6.67061616e-05,
                        1.33530078e-05,
                        6.24021345e-05,
                        2.99624528e-05,
                        1.46769445e-03,
                        5.88057530e-05,
                        2.93653545e-05,
                        2.59807730e-04,
                    ],
                    [
                        9.25241741e-05,
                        1.29907822e-04,
                        1.01799618e-04,
                        9.36385172e-05,
                        7.36769251e-05,
                        8.00058097e-05,
                        8.06056256e-05,
                        6.82970678e-05,
                        9.78971860e-05,
                        5.48727240e-05,
                        9.31736469e-05,
                        7.48882632e-05,
                        9.57482609e-05,
                        5.54946405e-05,
                        8.01716755e-05,
                        5.49979716e-05,
                        5.88057530e-05,
                        2.64386157e-04,
                        5.86401162e-05,
                        7.19687765e-05,
                    ],
                    [
                        6.38965633e-05,
                        8.45689814e-05,
                        4.94055789e-05,
                        9.41889951e-05,
                        4.43110756e-05,
                        5.07106300e-05,
                        7.45225568e-05,
                        4.66172115e-05,
                        5.25376833e-05,
                        5.19446849e-05,
                        5.04125987e-05,
                        4.35332486e-05,
                        7.10895859e-05,
                        6.18057249e-05,
                        4.58819945e-05,
                        6.12954234e-05,
                        2.93653545e-05,
                        5.86401162e-05,
                        1.79736391e-04,
                        4.53155349e-05,
                    ],
                    [
                        7.29294460e-05,
                        1.12013863e-04,
                        1.37587519e-04,
                        1.02646063e-04,
                        2.33878149e-04,
                        1.48126536e-04,
                        6.66373556e-05,
                        4.80990329e-05,
                        1.29197251e-04,
                        5.15497127e-05,
                        6.39314297e-05,
                        5.66260792e-05,
                        7.09214267e-05,
                        4.59275123e-05,
                        5.57058604e-05,
                        4.31980769e-05,
                        2.59807730e-04,
                        7.19687765e-05,
                        4.53155349e-05,
                        3.08482356e-04,
                    ],
                ]
            ),
        )


@pytest.mark.filterwarnings("ignore:invalid value encountered")
@pytest.mark.filterwarnings("ignore: overflow encountered in dot")
class TestGraphicalLassoCV:
    def test_fit(self, X):
        model = GraphicalLassoCV()
        model.fit(X)
        assert model.covariance_.shape == (20, 20)


class TestOAS:
    def test_fit(self, X):
        model = OAS()
        model.fit(X)
        assert model.covariance_.shape == (20, 20)


class TestLedoitWolf:
    def test_fit(self, X):
        model = LedoitWolf()
        model.fit(X)
        assert model.covariance_.shape == (20, 20)


class TestShrunkCovariance:
    def test_fit(self, X):
        model = ShrunkCovariance()
        model.fit(X)
        assert model.covariance_.shape == (20, 20)
